#ifndef KDTREE_H
#define KDTREE_H

#include "KDTreeNode.h"
#include "BoundingBox.h"

class KDTree
{
public:
//private:
	//Note: root node is an x-z plane (children are x-y then y-z and so on).
	KDTreeNode root;

//public:
	KDTree(size_t _targetTriangles, size_t _maxTreeDepth);
	~KDTree(void);

	//Loads a pre-built k-d tree in from a file (triangle intersection will still be re-calculated).
	//void loadTree(char* filename);

	void buildTree(vector<Triangle> *sceneTriangles, BoundingBox sceneBox);
	void buildTree(KDTreeNode *curNode, int axis, size_t depth);

	vector<Triangle*> getPossibleIntersections(Ray r, Point3 boxIn, Point3 boxOut);
	vector<Triangle*> getPossibleIntersections(Ray r, KDTreeNode* curNode, Point3 boxIn, Point3 boxOut, int axis);

private:
	size_t targetTriangles;
	size_t maxTreeDepth;
};

#endif